package com.ebelter.bodyfatscale.util;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.widget.TextView;

import com.ebelter.bodyfatscale.ApplicationHelper;
import com.ebelter.bodyfatscale.ui.pager.main.DashboardPager;
import com.ebelter.btlibrary.util.ULog;

/**
 * Created by pan on 2018/4/19
 */

public class StringUtils {

    public static final String TAG = "StringUtils";

    public static String getResStr(int strRes){
        return ApplicationHelper.mApplicationContecx.getString(strRes);
    }
    public static boolean isEmpty(String string){
        return string == null || string.length() == 0;
    }



    public static SpannableString getSpannableString(String content,int textSize,int start,int end){
        SpannableString spanString = new SpannableString(content);
        AbsoluteSizeSpan span = new AbsoluteSizeSpan(textSize);
        spanString.setSpan(span, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        return spanString;
    }



    public static void setTextUseSpannable(TextView textView,int value,String unit,int textSize){



        try {
            if (textView==null){
                return;
            }
            if (value<=0){
                textView.setText(DashboardPager.NO_RESULT);
            }else {
                String local = AppUtils.getLocalStr();
                String result;
                if (TextUtils.equals(local,AppUtils.iw)){
                    result =  unit+value;
                    ULog.i(TAG,"unitDisplay result1 = "+result);
                    SpannableString spannableString =getSpannableString(result,textSize,0,unit.length());
                    textView.setText(spannableString);

                }else {
                    //不需要取反的
                    result = value+unit;
                    ULog.i(TAG,"unitDisplay result2 = "+result);

                    if (TextUtils.equals(local,AppUtils.ru)){
                        SpannableString spannableString =getSpannableString(result,textSize,(value+"").length(),result.length());
                        textView.setText(spannableString);
                    }else {
                        textView.setText(result);
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }



    }


}
